/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	RenderEntrySwapChain.cpp
*
*	Comments	-	See RenderEntrySwapChain.h
*
**************************************************************************************/
#include "../Include/RenderEntrySwapChain.h"
#include "../Include/SwapChain.h"
#include "../Include/GraphicsPipeline.h"
#include "../Include/Texture2D.h"
#include "../Include/Color.h"

namespace Pulse
{
	RenderEntrySwapChain::RenderEntrySwapChain( void )
		: m_pSwapChain( PSX_NULL )
	{

	}

	RenderEntrySwapChain::~RenderEntrySwapChain( void )
	{
		PSX_SafeRelease( m_pSwapChain );
	}

	void RenderEntrySwapChain::SetSwapChain( SwapChain *pSwapChain )
	{
		PSX_SafeRelease( m_pSwapChain );

		m_pSwapChain = pSwapChain;

		if ( pSwapChain )
			pSwapChain->AddRef();
	}

	void RenderEntrySwapChain::Execute( GraphicsPipeline *pPipeline )
	{
		if ( m_pSwapChain == PSX_NULL )
		{
			PSX_PushWarning( "No swapchain to set as render target." );
			return;
		}

		pPipeline->OMClearStates();
		pPipeline->OMSetRenderTarget( 0, m_pSwapChain->GetBackBufferUnsafe() );
		pPipeline->OMSetDepthStencil( m_pSwapChain->GetDepthBufferUnsafe() );
		pPipeline->GetOutputMergerStage()->BindRenderTargets();
		
		pPipeline->OMClearRenderBuffers( &Color::BLACK );
	}

}